﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Light.Aop
{
    /// <summary>
    /// 支持缓存的方法特性
    /// </summary>
    [AttributeUsage(AttributeTargets.Method)]
    public class CacheMethodAttribute : Attribute
    {

        /// <summary>
        /// 缓存过期时间（有效时间）
        /// </summary>
        public double ExpiresSeconds { get; set; }

        /// <summary>
        /// 是否更新缓存
        /// </summary>
        public bool UpdateCache { get; set; }

        /// <summary>
        /// 缓存Key的前缀（用于生成缓存Key，优先取KeyPrefix）
        /// </summary>
        public string KeyPrefix { get; set; }

        /// <summary>
        /// 数据类型（用于生成缓存Key，优先取KeyPrefix，当KeyPrefix为空时，取Type.Name）
        /// </summary>
        public Type Type { get; set; }

        /// <summary>
        /// 构造函数：默认过期时间为1个小时
        /// </summary>
        public CacheMethodAttribute()
        {

            UpdateCache = false;
            this.ExpiresSeconds = 60 * 60;
        }

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="expiresSeconds">过期时间，秒</param>
        public CacheMethodAttribute(double expiresSeconds)
        {
            this.ExpiresSeconds = expiresSeconds;
        }
    }
}
